/***************************************************************************
*   Copyright (C) 2011 by Chuck Gao & Alex Liu                             *
*                                                                          *
*   This program is free software: you can redistribute it and/or modify   *
*   it under the terms of the GNU General Public License as published by   *
*   the Free Software Foundation, either version 3 of the License, or      *
*   (at your option) any later version.                                    *
*                                                                          *
*   This program is distributed in the hope that it will be useful,        *
*   but WITHOUT ANY WARRANTY; without even the implied warranty of         *
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
*   GNU General Public License for more details.                           *
*                                                                          *
*   You should have received a copy of the GNU General Public License      *
*   along with this program.  If not, see <http://www.gnu.org/licenses/>.  *
*                                                                          *
*   Contact author: chuckgao.cg@gmail.com                                  *
*                   alex2202375@gmail.com                                  *
***************************************************************************/

import QtQuick 1.0
import Qt.labs.shaders 1.0
import com.nokia.symbian 1.1
import Qt.labs.components 1.1

Item {
    id: demons

    ListModel {
        id: testModel
        ListElement { name: "宫保鸡丁" }
        ListElement { name: "回锅肉" }
        ListElement { name: "麻婆豆腐" }
        ListElement { name: "鱼香肉丝" }
    }

    Component {
        id: functionMenuDialogComponent
        SelectionDialog {
            titleText: "What do you want"
            selectedIndex: 1

            model: ListModel {
                ListElement { name: "Start Cook" }
                ListElement { name: "Go Shopping List" }
                ListElement { name: "Delete plan" }
                ListElement { name: "Edit plan" }
            }

            onAccepted: {
            }

            onRejected: {
            }
        }
    }

    Component {
        id: testDelegate
        Item {
            width: 360
            height: 535

            Image {
                id: image
                width: 240
                height: 320
                anchors.horizontalCenter: parent.horizontalCenter
                anchors.bottom: text.top
                anchors.bottomMargin: 20
                smooth: true
                fillMode: Image.Stretch
                source: "qrc:/plan/Images/Plan/kungpao.jpg"

                Rectangle {
                    id: roundedCorner
                    property int shadowMargin: -5

                    anchors {
                        fill: parent
                        leftMargin: shadowMargin; topMargin: shadowMargin;
                        rightMargin: shadowMargin; bottomMargin: shadowMargin
                    }
                    color: "transparent"
                    opacity: 0.9
                    smooth: true
                    border.width: 10
                    border.color: "white"
                    radius: 15
                }
            }

            Text {
                id: text
                anchors.horizontalCenter: parent.horizontalCenter
                anchors.bottom: parent.bottom
                anchors.bottomMargin: 20
                text: name
                font.family: "Freestyle Script"
                font.bold: false
                style: Text.Normal
                font.pointSize: 12
                verticalAlignment: Text.AlignVCenter
                horizontalAlignment: Text.AlignHCenter
            }

            MouseArea {
                anchors.fill: parent
                onClicked: {
                    waveAnim.stop()
                    layer.waveOriginX = mouseX / planDayView.width
                    layer.waveOriginY = mouseY / planDayView.height
                    waveAnim.start()
                }

                onPressAndHold: {
                    // Show popup menu|dialog
                    var dialog = functionMenuDialogComponent.createObject(demons)
                    dialog.open()
                }
            }
        }
    }

    Text {
        id: yearText
        x: 27
        y: 17
        width: 100
        text: "2011"
        font.pixelSize: 70
        smooth: true
        clip: true
        font.family: "Freestyle Script"
        verticalAlignment: Text.AlignVCenter
        horizontalAlignment: Text.AlignHCenter
        color: "white"
    }

    Text {
        id: text1
        x: 35
        y: 86
        text: "June 27"
        font.family: "Freestyle Script"
        font.pixelSize: 35
        verticalAlignment: Text.AlignVCenter
        horizontalAlignment: Text.AlignHCenter
        color: "white"
    }

    ListView {
        width: 360
        height: 535
        anchors.bottom: parent.bottom
        delegate: testDelegate
        model: testModel
        clip: true
        orientation: ListView.Horizontal
        preferredHighlightBegin: 0.5
        preferredHighlightEnd: 0.5
        highlightRangeMode: ListView.StrictlyEnforceRange
    }
}
